package com.jy.adscm.operation.purchase.controller;


import com.jy.adscm.operation.purchase.bean.Bomandsupplier;
import com.jy.adscm.operation.purchase.bean.QueryByPageParameter;
import com.jy.adscm.operation.purchase.service.BomandsupplierService;
import com.jy.adscm.support.SimpleCoreResponse;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;

import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

/**
 * <p>
 * bom和供应商管理配置表 前端控制器
 * </p>
 *
 * @author lzf
 * @since 2019-05-05
 */
@RestController
@RequestMapping("adscm/operation/bomandsupplier")
public class BomandsupplierController {
    @Autowired
    BomandsupplierService bomandsupplierService;
    @RequestMapping("insert")
    public SimpleCoreResponse insert(@RequestBody Bomandsupplier bomandsupplier){
        return new SimpleCoreResponse("200","新增成功",bomandsupplierService.insert(bomandsupplier));
    }
    @RequestMapping("update")
    public SimpleCoreResponse update(@RequestBody Bomandsupplier bomandsupplier){
        return new SimpleCoreResponse("200","修改成功",bomandsupplierService.updateById(bomandsupplier));
    }
    @RequestMapping("delete")
    public SimpleCoreResponse delete(@RequestParam Long id){
        return new SimpleCoreResponse("200","删除成功",bomandsupplierService.deleteById(id));
    }
    @RequestMapping("queryByPage")
    public SimpleCoreResponse query(@RequestParam(value = "currentPage", defaultValue = "1") Integer currentPage,
                                    @RequestParam(value = "pageSize",defaultValue = "10") Integer pageSize,
                                    @RequestParam(value = "sortBy", required = false) String sortBy,
                                    @RequestParam(value = "desc",required = false)boolean desc,
                                    @RequestParam(value = "key", required = false) String key){
        QueryByPageParameter queryByPageParameter=new QueryByPageParameter(currentPage,pageSize,sortBy,desc,key);
        return new SimpleCoreResponse("200","查询成功",bomandsupplierService.query(queryByPageParameter));
    }
    @RequestMapping("queryByBom")
    public SimpleCoreResponse query(){
        return new SimpleCoreResponse("200","查询bom名称成功",bomandsupplierService.queryByBom());
    }
}

